Skip to content

ci: tolerate perf comment write failures#1013

Merged
ryoppippi merged 1 commit into
mainfrom
codex/fix-perf-comment-upsert
May 17, 2026
Merged

ci: tolerate perf comment write failures#1013
ryoppippi merged 1 commit into
mainfrom
codex/fix-perf-comment-upsert

Conversation

@ryoppippi
Copy link
Copy Markdown
Owner

@ryoppippi ryoppippi commented May 17, 2026

Summary

  • always write ccusage perf results to the GitHub Actions job summary
  • keep PR comment publishing for normal same-repo PRs
  • fall back to a fresh comment when updating the marker comment fails
  • warn instead of failing when fork PR tokens cannot write comments

Why

Fork PRs can complete the perf comparison, but their pull_request GITHUB_TOKEN may not be allowed to write issue comments. The previous workflow failed after successful measurement because comment creation returned 403.

Validation

  • pnpm run format
  • pnpm typecheck

Summary by CodeRabbit

  • Chores
    • Improved error handling for GitHub API interactions with better permission failure detection
    • Enhanced PR comment creation and update flow with graceful fallback mechanisms
    • Added performance metrics visibility in GitHub Actions job summaries

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 17, 2026

📝 Walkthrough

Walkthrough

This PR adds typed error handling to the GitHub API request helper, introduces resilient comment creation functions that gracefully skip on permission errors, refactors the upsert flow to use fallback creation logic, and appends performance metrics to the GitHub Actions job summary.

Changes

GitHub PR comment error handling and resilience

Layer / File(s) Summary
Typed error class and request handler enhancement
.github/scripts/upsert-pr-comment.ts
GitHubRequestError class stores HTTP status, and githubRequest throws this typed error on non-OK responses instead of generic errors, enabling status-specific error handling downstream.
Comment creation with 403 resilience
.github/scripts/upsert-pr-comment.ts
createComment() POSTs the comment body; tryCreateComment() wraps it to catch 403 permission errors, log a warning, and return gracefully without failing the script.
Upsert flow with fallback retry
.github/scripts/upsert-pr-comment.ts
When no existing marker comment is found, uses tryCreateComment() to create it; when an existing comment is found, attempts PATCH and falls back to tryCreateComment() on failure instead of failing entirely.

GitHub Actions job summary integration

Layer / File(s) Summary
Job summary step
.github/workflows/ccusage-perf.yaml
New "Write job summary" step reads the generated performance comment markdown from $RUNNER_TEMP/ccusage-perf-comment.md and appends it to $GITHUB_STEP_SUMMARY after fixture comparison completes.

🎯 2 (Simple) | ⏱️ ~10 minutes

🐰 With errors typed and gracefully caught,

And summaries shown for all to see,

The CI comments now stay or fall,

Yet the script hops on, resilient and free! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title "ci: tolerate perf comment write failures" accurately captures the main objective of the PR: making the workflow resilient to comment write failures by logging warnings instead of failing.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/fix-perf-comment-upsert

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

.github/scripts/upsert-pr-comment.ts

[baseline-browser-mapping] The data in this module is over two months old. To ensure accurate Baseline data, please update: npm i baseline-browser-mapping@latest -D
tsconfig.json is not found. we cannot use type-aware rules.

Oops! Something went wrong! :(

ESLint: 9.35.0

Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'eslint-plugin-format' imported from /node_modules/.pnpm/@antfu+eslint-config@4.19.0_@vue+compiler-sfc@3.5.30_eslint@9.35.0_typescript@5.9.2_vit_670a2c5c75d4275eabd7bc195a173ee6/node_modules/@antfu/eslint-config/dist/index.js
at Object.getPackageJSONURL (node:internal/modules/package_json_reader:301:9)
at packageResolve (node:internal/modules/esm/resolve:764:81)
at moduleResolve (node:internal/modules/esm/resolve:855:18)
at defaultResolve (node:internal/modules/esm/resolve:988:11)
at #cachedDefaultResolve (node:internal/modules/esm/loader:697:20)
at #resolveAndMaybeBlockOnLoaderThread (node:internal/modules/esm/loader:714:38)
at ModuleLoader.resolveSync (node:internal/modules/esm/loader:746:52)
at #resolve (node:internal/modules/esm/loader:679:17)
at ModuleLoader.getOrCreateModuleJob (node:internal/modules/esm/loader:599:35)
at node:internal/modules/esm/loader:628:32


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Make the perf comment helper fall back to creating a new comment when updating the existing marker comment fails. If GitHub refuses comment writes, as it does for fork pull_request tokens, log a warning and let the performance comparison job finish successfully.

Validation: pnpm run format; pnpm typecheck
@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented May 17, 2026

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
ccusage-guide 3c23980 Commit Preview URL

Branch Preview URL
May 17 2026, 02:04 AM

@ryoppippi ryoppippi force-pushed the codex/fix-perf-comment-upsert branch from 589fe36 to 3c23980 Compare May 17, 2026 02:03
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 17, 2026

Open in StackBlitz

@ccusage/amp

npx https://pkg.pr.new/ryoppippi/ccusage/@ccusage/amp@1013

ccusage

npx https://pkg.pr.new/ryoppippi/ccusage@1013

@ccusage/codex

npx https://pkg.pr.new/ryoppippi/ccusage/@ccusage/codex@1013

@ccusage/opencode

npx https://pkg.pr.new/ryoppippi/ccusage/@ccusage/opencode@1013

@ccusage/pi

npx https://pkg.pr.new/ryoppippi/ccusage/@ccusage/pi@1013

commit: 3c23980

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 17, 2026

ccusage performance comparison

This compares the PR build against the base branch build on the same CI runner.

Committed fixture performance

Committed small fixtures for stable PR-to-PR feedback and explicit Claude/Codex command coverage.

Fixtures: Claude apps/ccusage/test/fixtures/claude (0.00 MiB, 2 files), Codex apps/ccusage/test/fixtures/codex (0.00 MiB, 1 files)
Runtime: package ccusage bin from apps/ccusage/package.json through bun -b, --offline --json, measured by hyperfine with 2 warmups and 7 runs.

Command Input Base median PR median PR vs base Base throughput PR throughput
claude daily --offline --json 0.00 MiB 54.0ms 54.5ms 0.99x 0.03 MiB/s 0.03 MiB/s
claude session --offline --json 0.00 MiB 53.7ms 54.9ms 0.98x 0.03 MiB/s 0.03 MiB/s
codex daily --offline --json 0.00 MiB 53.8ms 55.2ms 0.97x 0.02 MiB/s 0.02 MiB/s
codex session --offline --json 0.00 MiB 55.3ms 54.5ms 1.01x 0.02 MiB/s 0.02 MiB/s

Large real-world-shaped fixture performance

Generated fixtures shaped from aggregate local log statistics: thousands of JSONL files, many small sessions, and a long tail of larger sessions. No real prompts, paths, or outputs are stored in the fixtures.

Fixtures: Claude /home/runner/work/_temp/ccusage-large-fixture (1.01 GiB, 2,597 files), Codex /home/runner/work/_temp/ccusage-large-codex-fixture (1.01 GiB, 2,597 files)
Runtime: package ccusage bin from apps/ccusage/package.json through bun -b, --offline --json, measured by hyperfine with 0 warmups and 1 runs.

Command Input Base median PR median PR vs base Base throughput PR throughput
claude --offline --json 1.01 GiB 1.460s 1.579s 0.92x 706.23 MiB/s 653.02 MiB/s
codex --offline --json 1.01 GiB 1.503s 1.492s 1.01x 686.04 MiB/s 691.12 MiB/s

Package size

Package artifact Base PR Delta Ratio
packed ccusage-*.tgz 67.75 KiB 67.75 KiB +0.00 KiB 1.00x

Lower medians and smaller packed package sizes are better. CI runner noise still applies; use same-run ratios as directional PR feedback, not release guarantees.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.github/scripts/upsert-pr-comment.ts:
- Around line 91-99: The catch-all in the PATCH block (where githubRequest is
called to update `/issues/comments/${existing.id}`) should not unconditionally
call tryCreateComment on any local error; instead detect whether the update
actually failed server-side before creating a new marker: on error, re-fetch the
comment via githubRequest GET `/issues/comments/${existing.id}` (or inspect the
PATCH response status if available) and only call tryCreateComment when the GET
returns 404/410 or the PATCH returned a clear non-success HTTP status; if the
re-fetch shows the comment exists or the body matches the desired content, treat
the update as successful and do not create a new comment—apply this logic around
the existing githubRequest PATCH and tryCreateComment calls to avoid duplicate
marker comments.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 37691a89-54c0-4e8b-bcd9-e3443b245c0c

📥 Commits

Reviewing files that changed from the base of the PR and between 6e96ff7 and 3c23980.

📒 Files selected for processing (2)
  • .github/scripts/upsert-pr-comment.ts
  • .github/workflows/ccusage-perf.yaml

Comment on lines +91 to +99
try {
await githubRequest(`/repos/${repository}/issues/comments/${existing.id}`, {
method: 'PATCH',
body: JSON.stringify({ body }),
});
} catch (error) {
console.warn(`Failed to update existing PR comment; creating a new comment instead.`);
console.warn(error);
await tryCreateComment();
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Avoid posting a new marker comment after ambiguous update failures.

This catch-all will create a fresh comment even when the PATCH may already have succeeded server-side and only the response handling failed locally. That can leave duplicate marker comments on the PR, and later runs may keep updating the oldest one while stale copies remain visible.

Safer fallback
 	} catch (error) {
-		console.warn(`Failed to update existing PR comment; creating a new comment instead.`);
-		console.warn(error);
-		await tryCreateComment();
+		if (error instanceof GitHubRequestError && error.status === 404) {
+			console.warn(
+				'Existing PR comment no longer exists; creating a new comment instead.',
+			);
+			await tryCreateComment();
+			return;
+		}
+		throw error;
 	}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/scripts/upsert-pr-comment.ts around lines 91 - 99, The catch-all in
the PATCH block (where githubRequest is called to update
`/issues/comments/${existing.id}`) should not unconditionally call
tryCreateComment on any local error; instead detect whether the update actually
failed server-side before creating a new marker: on error, re-fetch the comment
via githubRequest GET `/issues/comments/${existing.id}` (or inspect the PATCH
response status if available) and only call tryCreateComment when the GET
returns 404/410 or the PATCH returned a clear non-success HTTP status; if the
re-fetch shows the comment exists or the body matches the desired content, treat
the update as successful and do not create a new comment—apply this logic around
the existing githubRequest PATCH and tryCreateComment calls to avoid duplicate
marker comments.

@ryoppippi ryoppippi merged commit b438b4d into main May 17, 2026
23 checks passed
@ryoppippi ryoppippi deleted the codex/fix-perf-comment-upsert branch May 17, 2026 02:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant